package com.feihao.zhou.demo03_c3p0Pool;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.*;

public class Testc3p0 {
    public static void main(String[] args) {


        try {
            /*//1.获取数据源：
            DataSource dataSource = new ComboPooledDataSource();
            //获取连接：
            Connection connection = dataSource.getConnection();*/

            Connection connection = DBUtisForC3P0.getConnection();

            //sql：
            String sql = "SELECT * FROM student";
            //获取执行对象：
            PreparedStatement preparedStatement = connection.prepareStatement(sql);

            //执行：
            ResultSet resultSet = preparedStatement.executeQuery();

            while (resultSet.next()) {
                int sid = resultSet.getInt("sid");
                String name = resultSet.getString("name");
                int age = resultSet.getInt("age");
                Date birthday = resultSet.getDate("birthday");
                System.out.println(sid + "," + name + "," + age + "," + birthday);
            }

            //关流：
            connection.close();
            resultSet.close();
            preparedStatement.close();

        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
